import { CANCEL_ORDER_URL, CART_DELETE_URL, CART_LIST_URL, CART_MODIFY_URL, FINISH_ORDER_URL, ORDER_ADD_URL, ORDER_URL } from "../config/cartUrl.cfg";
import { ADD_CART_URL } from "../config/productsUrl.cfg";
import request from "./ajax";

/**
 * @author liping
 * @time 2023-10-24 16:12 PM
 * @description 购物车数据接口
 */
// 获取购物车数据
export function getCartListApi(uid:string){
    return request({url:CART_LIST_URL + uid})
}

/** 添加商品到购物车 */ 
export function addProductApi(data:any){
    return request({
        url:ADD_CART_URL,
        data,
        method:'POST'
    })
}

/**修改购物车数据 */
export function cartModifyApi(data:CartModifyObj){
    return request({
        url:CART_MODIFY_URL,
        data,
        method:'POST'
    })
}

// 删除购物车数据
export function cartDeleteApi(data:CartDeleteObj){
    return request({
        url:CART_DELETE_URL,
        data,
        method:'DELETE'
    })
}

// 新增订单接口
export function orderAddApi(data:any){
    return request({
        url:ORDER_ADD_URL,
        data,
        method:'POST'
    })
}

/** 获取订单接口 */
export function getOrderListApi(userId:string,state:string){
    return request({
        url:ORDER_URL + userId,
        params:{state}
    })
} 

/** 完成订单接口 */ 
export function finishOrderApi(userId:string,id:string){
    return request({
        url:FINISH_ORDER_URL,
        data:{userId,id},
        method:'POST'
    })
} 

/** 取消订单接口 */ 
export function cancelOrderApi(userId:string,id:string){
    return request({
        url:CANCEL_ORDER_URL,
        data:{userId,id},
        method:'POST'
    })
} 